package lib

import "fmt"

func MQInit() error {

	mqconn := NewMq()

	err := mqconn.Ch.ExchangeDeclare(EXCHANGE_USER, "direct", false, false, false, false, nil)
	if err != nil {
		fmt.Println(err)
		return err
	}

	q := fmt.Sprintf("%s,%s", QUEUE_NEW_USER, QUEUW_NEW_USER_UNION)
	err = mqconn.DecQueueAndBind(q, ROUTER_KEY_USER_REG, EXCHANGE_USER)
	if err != nil {
		fmt.Println(err)
		return err
	}

	return nil

}

//NewDelayedInitMQ 延迟发送消息
func NewDelayedInitMQ() error {

	mqconn := NewMq()

	//延迟发送消息
	err := mqconn.Ch.ExchangeDeclare(EXCHANGE_USER_DELAYED, "x-delayed-message",
		false, false, false, false,
		map[string]interface{}{"x-delayed-type": "direct"})
	if err != nil {
		fmt.Println(err)
		return err
	}

	err = mqconn.DecQueueAndBind(QUEUE_NEW_USER, ROUTER_KEY_USER_REG, EXCHANGE_USER_DELAYED)
	if err != nil {
		fmt.Println(err)
		return err
	}

	return nil

}
